({
    Init: function(cmp, event, helper) {
        //获取搜索条件
        var searchKeyWord = cmp.get("v.searchKeyWord");
        // 调用后台类
        var action = cmp.get("c.getMyAccounts");

        // 设置请求参数
        action.setParams({
            searchKeyWord: searchKeyWord,
        });
        // 设置回调函数
        action.setCallback(this, function(response) {
            // 返回状态
            var state = response.getState();
            if (state == 'SUCCESS') {
                var accountList = response.getReturnValue();
                // 参数传递
                cmp.set("v.results", accountList);
                cmp.set("v.count", accountList.length);
            } else {
                // 处理错误情况
                console.error('Error: ' + response.getError());
            }
            var currentPage = cmp.get("v.currentPage");
            var pageSize = cmp.get("v.pageSize");
            var startIndex = (currentPage - 1) * pageSize; // 起始索引（包含）
            var endIndex = startIndex + pageSize; // 结束索引（不包含）

            let items = [];
            const accounts = cmp.get("v.results");
            for (let i = startIndex; i < endIndex; i++) {
                items.push(accounts[i]); 
            }
            cmp.set('v.items', items);
        });
        // 队列处理
        $A.enqueueAction(action);
    },

    getPage: function(cmp, currentPage, pageSize) {
        const count = cmp.get('v.count');
        const startIndex = (currentPage - 1) * pageSize; // 起始索引（包含）
        const endIndex = Math.min(startIndex + pageSize, count); // 结束索引（不包含）
      
        const accounts = cmp.get("v.results");
        const items = accounts.slice(startIndex, endIndex);
        cmp.set('v.items', items);
      }
})